import { getAreaObj, uploadType } from '@/utils/util'

export const importConfig = {
	tabSteps: [
		{
			label: '下载模板',
			download: '下载模板',
			active: 1,
			rules: [
				{
					label: '下载最新导入模板。共1个：',
					children: [
						{
							label: '《招标情况信息表》',
							link: true,
							url: 'view_lfBiddingSituation_downloadTemplate',
						},
					],
				},
			],
		},
		{
			label: '导入招标情况信息',
			description: '',
			uploadTip: '招标情况信息表',
			active: 2,
			url: 'view_lfBiddingSituation_import',
			code: 5001,
			rules: [
				{
					label: '导入规则说明:',
					children: [{ label: '(1)导入模式为“覆盖导入”，待导入的服务对象的信息会覆盖平台已存在的' }],
				},
			],
		},
	],
}

export const formConfig = {
	inline: false,
	showBtn: true,
	labelPosition: 'top',
	labelWidth: '120px',
	column: [
		{
			type: 'DividerHtml',
			labelPosition: 'top',
			position: 'center',
			modelValue: '采购意向',
			span: 24,
		},
		{
			label: '所属区',
			prop: 'areas',
			propName: 'areasName',
			type: 'AplidAreaSelect',
			regionGrade: 3,
			checkStrictly: false,
			authArea: true,
			disabled: true,
			span: 12,
		},
		{
			label: '招标内容',
			prop: 'contentType',
			propName: 'contentTypeLabel',
			type: 'remoteSelect',
			code: 'BIDDING_CONTENT',
			api: 'getDictItemList',
			filterKey: 'value',
			multiple: false,
			defaultValue: 1,
			span: 12,
		},
		{
			label: '所属年份',
      defaultValue: new Date().getFullYear(),
			type: 'input',
      disabled:true,
			span: 12,
		},
		{
			label: '采购意向公告时间',
			prop: 'purchaseIntentionTime',
			format: 'YYYY年MM月DD日',
			valueFormat: 'YYYY-MM-DD',
			type: 'date',
			span: 12,
		},
		{
			label: '附件',
			prop: 'intentionEnclosure',
			type: 'upload',
			custome: 'file',
			fileType: uploadType.fileMetaType,
			listType: 'picture-card',
			labelPosition: 'top',
			showFileList: true,
			limit: 4,
			multiple: true,
			span: 24,
			showLabel: false,
		},
		{
			type: 'DividerHtml',
			labelPosition: 'top',
			position: 'center',
			modelValue: '采购（征集）',
			span: 24,
		},
		{
			label: '采购（征集）公告时间',
			prop: 'procurementSolicitationTime',
			format: 'YYYY年MM月DD日',
			valueFormat: 'YYYY-MM-DD',
			type: 'date',
			span: 24,
		},
		{
			label: '附件',
			prop: 'solicitationEnclosure',
			type: 'upload',
			custome: 'file',
			fileType: uploadType.fileMetaType,
			listType: 'picture-card',
			labelPosition: 'top',
			showFileList: true,
			limit: 4,
			multiple: true,
			span: 24,
			showLabel: false,
		},
		{
			type: 'DividerHtml',
			labelPosition: 'top',
			position: 'center',
			modelValue: '结果（入围）',
			span: 24,
		},
		{
			label: '结果入围公告时间',
			prop: 'resultShortlistedTime',
			format: 'YYYY年MM月DD日',
			valueFormat: 'YYYY-MM-DD',
			type: 'date',
			span: 12,
		},
		{
			label: '中标单位',
			prop: 'winningBidder',
			maxlength: '120',
			showWordLimit: true,
			type: 'text',
			span: 12,
		},
		{
			label: '附件',
			prop: 'shortlistedEnclosure',
			type: 'upload',
			custome: 'file',
			fileType: uploadType.fileMetaType,
			listType: 'picture-card',
			labelPosition: 'top',
			showFileList: true,
			limit: 4,
			multiple: true,
			span: 24,
			showLabel: false,
		},
		{
			type: 'DividerHtml',
			labelPosition: 'top',
			position: 'center',
			modelValue: '合同公告',
			span: 24,
		},
		{
			label: '合同公告时间 ',
			prop: 'contractTime',
			format: 'YYYY年MM月DD日',
			valueFormat: 'YYYY-MM-DD',
			type: 'date',
			span: 24,
		},
		{
			label: '附件',
			prop: 'contractEnclosure',
			type: 'upload',
			custome: 'file',
			fileType: uploadType.fileMetaType,
			listType: 'picture-card',
			labelPosition: 'top',
			showFileList: true,
			limit: 4,
			multiple: true,
			span: 24,
			showLabel: false,
		},
	],
}

export const searchConfig = {
	inline: true,
	showBtn: true,
	labelPosition: 'left',
	column: [
		{
			label: '所属区',
			prop: 'areas',
			type: 'AplidAreaSelect',
			regionGrade: 3,
			checkStrictly: false,
			span: 8,
		},
		{
			label: '招标内容',
			prop: 'contentType',
			propName: 'contentTypeLabel',
			type: 'remoteSelect',
			code: 'BIDDING_CONTENT',
			api: 'getDictItemList',
			dataType: 'number',
			filterKey: 'value',
			multiple: false,
			span: 8,
		},
		{
			label: '招标进度',
			prop: 'biddingProgress',
			propName: 'biddingProgressLabel',
			type: 'remoteSelect',
			code: 'BIDDING_PROGRESS',
			api: 'getDictItemList',
			dataType: 'number',
			filterKey: 'value',
			multiple: false,
			span: 8,
		},
		{
			label: '中标单位',
			prop: 'winningBidder',
			type: 'input',
			span: 8,
		},
		// {
		// 	label: '项目开始日期',
		// 	prop: 'startDateBetween',
		// 	format: 'YYYY年MM月DD日',
		// 	valueFormat: 'YYYY-MM-DD HH:mm:ss',
		// 	type: 'dateBetween',
		// 	span: 8,
		// },
	],
}

export const tableConfig = {
	stripe: true,
	border: true,
	columns: [
		{ label: '所属区', prop: 'areaName' },
		{ label: '招标内容', prop: 'contentTypeLabel' },
		{
			label: '中标单位',
			prop: 'winningBidder',
		},
		{
			label: '招标进度',
			prop: 'biddingProgress',
			custome: 'tag',
			dicData: [
				{ label: '未招标', value: 1, type: 'primary' },
				{ label: '启动招标', value: 2, type: 'success' },
				{ label: '招标完成', value: 3, type: 'warning' },
			],
		},
		{
			label: '操作',
			prop: 'menu',
			width: 300,
			fixed: 'right',
		},
	],
}

export const api = {
	index: 'view_lfBiddingSituation_page',
	add: 'view_lfBiddingSituation_add',
	edit: 'view_lfBiddingSituation_edit',
	delete: 'view_lfBiddingSituation_del',
	detail: 'view_lfBiddingSituation_view',
	// export: 'view_lfBiddingSituation_export',
	// import: 'view_lfBiddingSituation_import',
}
export const auth = {
	...api,
}
export const baseConfig = {
	pageName: '招标情况',
	dictcodes: ['COMMON_FLAG', 'BIDDING_CONTENT', 'BIDDING_PROGRESS'],
	rowKey: 'id',
	addLabel: '新增',
	tipLabel: 'contentTypeLabel',
	exportMqTopic: '/ning/export/',
	importLabel: '导入',
	api,
	auth,
	menuBtn: [
		{
			icon: 'editor',
			label: '编辑',
			type: 'primary',
			operate: 'edit',
			auth: auth.edit,
			text: true,
			show: true,
		},
		{
			icon: 'delete',
			label: '删除',
			type: 'danger',
			operate: 'delete',
			auth: auth.delete,
			text: true,
			show: true,
		},
		{
			icon: 'detail',
			label: '详情',
			type: 'primary',
			operate: 'detail',
			auth: auth.index,
			text: true,
			show: true,
		},
	],
	saveFormate: async (form) => {
		return new Promise((resolve, reject) => {
			const areasObj: any = getAreaObj(form.areas, '')
			const areasNameObj: any = getAreaObj(form.areasName, '')
			if (form.winningBidder) {
				form.biddingProgress = 3
				form.biddingProgressLabel = '招标完成'
			} else if (form.contractTime || form.purchaseIntentionTime || form.procurementSolicitationTime) {
				form.biddingProgress = 2
				form.biddingProgressLabel = '启动招标'
			}
			resolve({
				...form,
				...areasObj,
				...areasNameObj,
				areas: undefined,
				areasName: undefined,
			})
		})
	},
	beforeOnLoadFormate: async (query) => {
		return new Promise((resolve, reject) => {
			const areasObj: any = getAreaObj(query.areas, '')
			resolve({
				...query,
				...areasObj,
				areas: undefined,
        year:new Date().getFullYear()
			})
		})
	},
	operateFormate: async (row, type) => {
		return new Promise((resolve, reject) => {
			if (type == 'detail') {
				const areasObj: any = getAreaObj(row, '', 'set')
				row.areasName = areasObj.names
			}
			resolve({
				...row,
			})
		})
	},
	dialogConfig: {
		width: '65%',
	},
	searchConfig,
	formConfig,
	tableConfig,
	importConfig,
	detailConfig: formConfig,
}
